package de.karlNet.sambamanager.ldapController.commands;

import javax.naming.NamingException;
import javax.naming.directory.BasicAttribute;

import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Controller;

import de.karlNet.sambamanager.ldapModel.dto.LdapGroupModifyDTO;

@Controller
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class ModifyGroup extends BaseCommand {

	public void modifyGroupItself(LdapGroupModifyDTO ldapGroup)
			throws NamingException {
		SimpleModificationCommand modificationCommand = new SimpleModificationCommand(
				this.ldapTemplate, ldapGroup.getOldGroup().getDn());
		BasicAttribute samaccountname = new BasicAttribute("samaccountname",
				ldapGroup.getLdapGroup().getCn());
		modificationCommand.simpleModification(samaccountname);
		modificationCommand.execute();

		this.ldapTemplate.rename(ldapGroup.getOldGroup().getDn(), ldapGroup
				.getLdapGroup().getDn());
	}
}
